#include "qcustombutton.h"
#include <QMouseEvent>

QCustomButton::QCustomButton(int index, QWidget *parent)
    : QPushButton(parent),
    m_index(index)
{
    setIcon(QIcon(":/icon.png"));
    setStyleSheet("QPushButton {"
                  "  border: none;"
                  "  background-color: transparent;"
                  "}"
                  "QPushButton:hover {"
                  "  color: blue;"
                  "}"
                  "QPushButton:pressed {"
                  "  color: red;"
                  "  border-style: inset;"
                  "}");

    // 存储按钮在列表中的索引
    m_index = index;
}

void QCustomButton::mousePressEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        emit clicked(m_index);
    }
    QPushButton::mousePressEvent(event);
}
